//
//  ZYUserAccount.swift
//  SwiftDemo1
//
//  Created by wangzhipan on 2025/6/13.
//

import Foundation

struct ZYUserTempInfo: Codable {
    var screen_name: String?
    var avatar_large: String?
}

class ZYUserAccount:NSObject, NSCoding, Codable {
    
//    static var supportsSecureCoding: Bool = false
    var access_token: String?
    
    /// 过期时间-->秒
    var expires_in: TimeInterval = 0
    
    /// 用户ID
    var uid : String?
    /// 过期日期
    var expires_date : Date {
        return Date(timeIntervalSinceNow: expires_in)
    }
    /// 昵称
    var screen_name : String?
    /// 用户的头像地址
    var avatar_large : String?
    
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeys(dict)
    }
    
    override class func setValue(_ value: Any?, forUndefinedKey key: String) {}
    
    required init?(coder: NSCoder) {
        super.init()
        access_token = coder.decodeObject(forKey: "access_token") as? String
        expires_in = coder.decodeDouble(forKey: "expires_in")
        uid = coder.decodeObject(forKey: "uid") as? String
//        expires_date = coder.decodeObject(forKey: "expires_date") as? Date
        screen_name = coder.decodeObject(forKey: "screen_name") as? String
        avatar_large = coder.decodeObject(forKey: "avatar_large") as? String
    }
    
    func encode(with coder: NSCoder) {
        coder.encode(access_token, forKey: "access_token")
        coder.encode(expires_in, forKey: "expires_in")
        coder.encode(uid, forKey: "uid")
//        coder.encode(expires_date, forKey: "expires_date")
        coder.encode(screen_name, forKey: "screen_name")
        coder.encode(avatar_large, forKey: "avatar_large")
    }
    
}
